import { findAllLine, addLine, updateLine, delLine, findLine } from '@/apis/lineApi'
import { defineStore } from 'pinia'
import { ref } from 'vue'

const line = ref<LineDataInter>()
const lines = ref<LineDataInter[]>([])

export default defineStore('line', () => {
  async function all(args: Record<string, any>) {
    const { data } = await findAllLine(args)
    lines.value = data
  }

  async function add(data: LineDataInter) {
    return await addLine(data)
  }

  async function update(id: number, data: LineDataInter) {
    return await updateLine(id, data)
  }

  async function del(id: number) {
    return await delLine(id)
  }
  async function find(id: number) {
    const res = await findLine(id)
    line.value = res.data
  }

  return { line, lines, all, add, update, del, find }
})
